home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C# & Game Programming - A…er's Guide (2nd Edition)
/
Buono 2nd Ed.iso
/
Chapter4
/
4.26
/
4.26.cs
next >
Wrap
Text File
|
2004-10-26
|
981b
|
28 lines
/* Assigning values and memory locations to pointers. */
using System;
namespace Chapter4 {
class Class1 {
static unsafe void Main() {
int* pointer1, pointer2;
// Warning, pointer3 is not an actual pointer!
int variable1 = 1, pointer3;
// Assigning a pointer to a value
pointer1 = &variable1;
// Pointer to pointer assignments DO NOT require the asterisk.
pointer2 = pointer1;
// Pointers can also pass values to variables.
pointer3 = *pointer2;
Console.WriteLine("{0} {1} {2} {3}",
variable1, *pointer1, *pointer2, pointer3);
*pointer1 = 20; // the value inside that address is now 20.
Console.WriteLine("{0} {1} {2} {3}",
variable1, *pointer1, *pointer2, pointer3);
}
}
}